/** 
 * UnmodifiableIterator.java
 * @author Lex
 * 2007-8-21 ����06:41:18
 */
package org.lex.utils.collections;

import java.util.Iterator;

/**
 * ��֧��<code>remove()</code>������Iterator
 * ʵ�ʹ�����Enumeration�ӿ�,����ȴ�ܹ�����Java Collections Framework��
 * 
 * ������ʵ������װ����ģʽ��һ������,�Թ��캯���д��ݽ�����Iterator����
 * װ��,�����䲿�ֹ���(ɾ�����)
 */
public class UnmodifiableIterator<T> implements Iterator<T> {
	private static final String ERROR = "Operation remove() not supported";
	private static final UnsupportedOperationException UOE = new UnsupportedOperationException(ERROR);

	protected Iterator<T> iterator = null;

	public static <T> UnmodifiableIterator<T> decorate(Iterator<T> iter) {
		return new UnmodifiableIterator<T>(iter);
	}

	public UnmodifiableIterator(Iterator<T> iter) {
		this.iterator = iter;
	}

	public boolean hasNext() {
		return iterator.hasNext();
	}

	public T next() {
		return iterator.next();
	}

	public final void remove() throws UnsupportedOperationException {
		throw UOE;
	}
}
